﻿<cfsilent>
	<cfsetting requesttimeout="90" />
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		chooseProp = getProperty("serviceFactory").getBean("choosePropertyAdvice");
		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");

		termId = event.getArg("TermID");

		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		
		/* 读取学生的已选课程 */ 
		sql="	SELECT c.cid,c.course_name,
					   c.course_credit,e.turn,
					   a.task_type,a.scc_id,
					   a.st,a.retaking,
					   a.choose_time,a.choose_prop,
					   a.task_id,d.prop_name 
				FROM t_student_course a 
					 INNER JOIN t_student b ON a.stu_id = b.stu_id 
					 INNER JOIN t_course c ON a.cid = c.cid 
					 INNER JOIN t_course_prop d ON a.prop_id = d.prop_id 
					 INNER JOIN t_choose_turn e ON a.ct = e.ct 
					 INNER JOIN t_term f ON a.term_id = f.term_id 
				WHERE b.stu_id = :studentId 
					  AND 
					  f.term_id = :termId 
				ORDER BY a.st, d.prop_name,c.course_name ";
		queryObj = new Query( datasource=application.dnsSlave ); 
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		rs_choosen = queryObj.execute( sql=sql ).getResult();
		
	</cfscript>
</cfsilent>

<cfif rs_choosen.recordCount>
	<table class="UIEditable">
		<thead>
			<tr>
				<td width="18"></td>
				<td>教学班</td>
				<td>任课教师</td>
				<td>学分</td>
				<!---<td>开课类别</td>--->
				<td>修读方式</td>
				<td>课程性质</td>
				<td>重修</td>
				<td>选课轮次</td>
				<td>选课时间</td>
				<td width="18"></td>
			</tr>
		</thead>
		<tbody>
			<cfset row = 0 />
        		<cfloop query="rs_choosen" >
				<cfset row++ />
			
				<!--- 读取教学任务教师和任务性质 ---> 
                <cfswitch expression="#rs_choosen.task_type#">
					<cfcase value="P">
                        <cfset sql="SELECT b.tch_name,c.campus_name,
										   a.task_week,
										   case when a.task_time is null then '-' else a.task_time end task_time ,
										   case when a.task_place is null then '-' else a.task_place end task_place,
										   a.task_prop,a.cidx 
									FROM t_task a 
										 INNER JOIN t_teacher b ON a.tch_id = b.tch_id 
										 INNER JOIN t_campus c ON a.campus_id = c.campus_id 
									WHERE a.tsk_id = :taskId "/>
                         
					</cfcase>
					<cfcase value="C">
                        <cfset sql="SELECT b.tch_name,c.campus_name,
										   a.task_week,
										   case when a.task_time is null then '-' else a.task_time end task_time ,
										   case when a.task_place is null then '-' else a.task_place end task_place,
										   a.task_prop,a.cidx 
									FROM t_common_task a 
										 INNER JOIN t_teacher b ON a.tch_id = b.tch_id 
										 INNER JOIN t_campus c ON a.campus_id = c.campus_id 
									WHERE a.tsk_id = :taskId "/>
                        
					</cfcase>
					<cfcase value="R">
                        <cfset sql="SELECT b.tch_name,c.campus_name,
										   a.task_week,
										   case when a.task_time is null then '-' else a.task_time end task_time ,
										   case when a.task_place is null then '-' else a.task_place end task_place,
										   a.task_prop,a.cidx 
									FROM t_reopen_task a 
										 INNER JOIN t_teacher b ON a.tch_id = b.tch_id 
										 INNER JOIN t_campus c ON a.campus_id = c.campus_id 
									WHERE a.tsk_id = :taskId "/>
                         
					</cfcase>
					<cfcase value="T">
                        <cfset sql="SELECT b.tch_name,c.campus_name,
										   a.task_week,
										   case when a.task_time is null then '-' else a.task_time end task_time ,
										   case when a.task_place is null then '-' else a.task_place end task_place,
										   a.task_prop,a.cidx 
									FROM t_sport_task a 
										 INNER JOIN t_teacher b ON a.tch_id = b.tch_id 
										 INNER JOIN t_campus c ON a.campus_id = c.campus_id 
									WHERE a.tsk_id = :taskId "/>
                        
					</cfcase>
				</cfswitch>
                <cfset queryObj = new Query( datasource=application.dnsSlave ) />
                <cfset queryObj.addParam( name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar" )/>
                <cfset rs_task = queryObj.execute( sql=sql ).getResult()/>
                
				<cfif rs_task.recordCount>
					<!--- 如果教学任务有效 ---> 
					<cfset taskProp.parseProperty( rs_task.task_prop ) />
					<cfset chooseProp.parseProperty( rs_choosen.choose_prop ) />
					<tr class="editRows <cfif rs_choosen.st eq "R">noticeRow1</cfif> <cfif rs_choosen.st eq "F">noticeRow2</cfif>">
						<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
						<td><cfoutput>#rs_choosen.course_name#</cfoutput>.-.<span class="numeric">(<cfoutput>#rs_task.cidx#</cfoutput>)</span></td>
						<td><cfoutput>#rs_task.tch_name#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#numberFormat(rs_choosen.course_credit, '_.__')#</cfoutput></span></td> 
						<td><cfoutput>#dictAdvice.getStudyType( rs_choosen.st )#</cfoutput></td>
						<td><cfoutput>#rs_choosen.prop_name#</cfoutput></td>
						<td><cfif rs_choosen.retaking eq "1">是</cfif></td>
						<td><cfoutput>#rs_choosen.turn#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosen.choose_time, 'YYYY-MM-DD HH:MI')#</cfoutput></span></td>
						<td>
							<cfif taskProp.getDischarge()>
									<span title="该教学班正在或已完成成绩录入，禁止退课" class="stat locked"></span>
								<cfelseif chooseProp.getLocked()>
									<span title="该选课记录禁止修改" class="stat locked"></span>
								<cfelseif chooseProp.getCharged()>
									<span title="该选课记录已结算" class="stat locked"></span>
								<cfelse>
									<cfset string = rs_choosen.cid & rs_task.cidx & termId & rs_choosen.task_type />
									<cfset key = rs_choosen.task_id />
									<cfset sign = encrypt(string, key, "PBEWithMD5AndDES", "Hex") />
									<a title="撤销课程" class="stat delete" href="javascript:removeTask('<cfoutput>#rs_choosen.scc_id#</cfoutput>','<cfoutput>#rs_choosen.cid#</cfoutput>','<cfoutput>#rs_task.cidx#</cfoutput>','<cfoutput>#termId#</cfoutput>','<cfoutput>#rs_choosen.task_type#</cfoutput>','<cfoutput>#rs_choosen.task_id#</cfoutput>','<cfoutput>#sign#</cfoutput>');"></a>
							</cfif>
						</td>
					</tr>
					<cfelse>
					<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
				</cfif>
			</cfloop>
		</tbody>
	</table>
</cfif>
